Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Do browsers assure that if an inline css property has not been set, the value of "element.style.property" will always be a empty string?

For example:

<xxx id="myid" ...></xxx>

If no code or nobody sets the inline css properties of element "xxx", then document.getElementById("myid").style.property always equals ""?

Do w3c standards or all browsers assure it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

On Blink based browsers, it seems to always set it to an empty string.

MDN recommends clearing them by setting them to null, which then isn't an empty string, but upon testing this in a blink based browser, it seems to reset to an empty string. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

On some browsers, when a CSS property hasn't been set, it is literally undefined, which is quite different from null or "" (an empty string).

You can force some consistency between all browsers and updated values by coercing to an empty string.

document.getElementById("myid").style.property || ""

Edit - New properties

CSS is rapidly changing, with new properties appearing frequently. As such, it got me thinking, what happens in blink based browsers with unrecognised properties.

The answer is not consistent with known properties, and instead, they are undefined if not set. Equally these can be set to null.

I would recommend using falsy checks when appropriate to solve this problem.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!